package com.ssy.lingxi.order.serviceimpl.feign;

import com.ssy.lingxi.common.constant.basic.FundModeEnum;
import com.ssy.lingxi.common.model.dto.MemberAndRoleIdDTO;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberDetailFeign;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberInnerControllerFeign;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberLevelRightCreditControllerFeign;
import com.ssy.lingxi.member.merchant.api.feign.inner.MemberOrderCommentControllerFeign;
import com.ssy.lingxi.member.merchant.api.model.constant.MemberRightSpendTypeEnum;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.*;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.response.*;
import com.ssy.lingxi.order.entity.OrderDO;
import com.ssy.lingxi.order.model.bo.VendorBO;
import com.ssy.lingxi.order.model.dto.*;
import com.ssy.lingxi.order.model.vo.basic.request.OrderDeductionVO;
import com.ssy.lingxi.order.service.feign.IMemberFeignService;
import com.ssy.lingxi.order.utils.OrderStringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 会员服务Feign接口调用类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-23
 */
@Service
public class MemberFeignServiceImpl implements IMemberFeignService {
    private static final Logger logger = LoggerFactory.getLogger(MemberFeignServiceImpl.class);

    @Resource
    private MemberLevelRightCreditControllerFeign memberLevelRightCreditControllerFeign;

    @Resource
    private MemberInnerControllerFeign memberInnerControllerFeign;

    @Resource
    private MemberOrderCommentControllerFeign memberOrderCommentControllerFeign;

    @Resource
    private MemberDetailFeign memberDetailFeign;

    /**
     * （异步）通知会员服务，计算等级、权益、积分
     * @param buyerMemberId  采购商会员Id
     * @param buyerRoleId    采购商会员角色Id
     * @param vendorMemberId 供应商会员Id
     * @param vendorRoleId   供应商会员角色Id
     * @param amount         订单金额
     * @param orderNo        订单号
     */
    @Async
    @Override
    public void calculateMemberLrcAsync(Long buyerMemberId, Long buyerRoleId, Long vendorMemberId, Long vendorRoleId, BigDecimal amount, String orderNo) {
        try {
            MemberFeignOrderVO orderVO = new MemberFeignOrderVO();
            orderVO.setUpperMemberId(vendorMemberId);
            orderVO.setUpperRoleId(vendorRoleId);
            orderVO.setSubMemberId(buyerMemberId);
            orderVO.setSubRoleId(buyerRoleId);
            orderVO.setOrderNo(orderNo);
            orderVO.setAmount(amount.doubleValue());
            logger.info("通知会员服务，计算等级、权益、积分 => " + OrderStringUtil.serializeObject(orderVO));
            Wrapper<MemberFeignReturnRightVO> returnRight = memberLevelRightCreditControllerFeign.calculateMemberLrcByOrder(orderVO);
            if (returnRight.getCode() != ResponseCode.SUCCESS.getCode()) {
                logger.error("通知会员服务，计算等级、权益、积分错误：" + returnRight.getMessage());
            }
        } catch (Exception e) {
            logger.error("通知会员服务，计算等级、权益、积分错误：" + e.getMessage());
        }
    }

    /**
     * 通知会员服务，计算等级、权益、积分
     * @param buyerMemberId  采购商会员Id
     * @param buyerRoleId    采购商会员角色Id
     * @param vendorMemberId 供应商会员Id
     * @param vendorRoleId   供应商会员角色Id
     * @param amount         订单金额
     * @param orderNo        订单号
     * @return 订单返现金额
     */
    @Override
    public Wrapper<BigDecimal> calculateMemberLrc(Long buyerMemberId, Long buyerRoleId, Long vendorMemberId, Long vendorRoleId, BigDecimal amount, String orderNo) {
        MemberFeignOrderVO orderVO = new MemberFeignOrderVO();
        orderVO.setUpperMemberId(vendorMemberId);
        orderVO.setUpperRoleId(vendorRoleId);
        orderVO.setSubMemberId(buyerMemberId);
        orderVO.setSubRoleId(buyerRoleId);
        orderVO.setOrderNo(orderNo);
        orderVO.setAmount(amount.doubleValue());
        Wrapper<MemberFeignReturnRightVO> returnRight = memberLevelRightCreditControllerFeign.calculateMemberLrcByOrder(orderVO);
        if (returnRight.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(returnRight.getCode(), returnRight.getMessage());
        }

        return Wrapper.success(BigDecimal.valueOf(returnRight.getData().getReturnMoney()));
    }

    /**
     * 积分支付订单，校验可用信用积分、支付密码
     * @param buyerMemberId            采购会员Id
     * @param buyerRoleId              采购会员角色Id
     * @param vendorMemberId           供应会员Id
     * @param vendorRoleId             供应会员角色Id
     * @param fundMode                 资金归集模式，1-平台代收，2-会员直接到账
     * @param payPassword              前端传递的Aes加密后的支付密码
     * @param memberRightSpendTypeEnum 积分消费类型枚举
     * @param payAmount                使用的积分
     * @param orderNo                  订单号
     * @return 校验结果
     */
    @Override
    public Wrapper<Void> calculateMemberUsedRightPoint(Long buyerMemberId, Long buyerRoleId, Long vendorMemberId, Long vendorRoleId, Integer fundMode, String payPassword, MemberRightSpendTypeEnum memberRightSpendTypeEnum, BigDecimal payAmount, String orderNo) {
        MemberFeignRightSpendVO spendVO = new MemberFeignRightSpendVO();
        spendVO.setUpperMemberId(vendorMemberId);
        spendVO.setUpperRoleId(vendorRoleId);
        spendVO.setSubMemberId(buyerMemberId);
        spendVO.setSubRoleId(buyerRoleId);
        spendVO.setRelType(fundMode.equals(FundModeEnum.PLATFORM_EXCHANGE.getCode()) ? 0 : 1);
        spendVO.setPayPassword(payPassword);
        spendVO.setUsedPoint(payAmount.intValue());
        spendVO.setSpentType(memberRightSpendTypeEnum.getTypeEnum());
        spendVO.setOrderNo(orderNo);
        return memberLevelRightCreditControllerFeign.calculateMemberUsedRightPoint(spendVO);
    }

    /**
     * 批量查询会员价格权益（会员折扣）
     * @param vendorRelations 会员关系列表
     * @return 查询结果
     */
    @Override
    public Wrapper<List<MemberFeignRelationRightDetailVO>> batchFindMemberPriceRight(List<MemberFeignRelationVO> vendorRelations) {
        vendorRelations = vendorRelations.stream().distinct().collect(Collectors.toList());
        if (CollectionUtils.isEmpty(vendorRelations)) {
            return Wrapper.success(new ArrayList<>());
        }

        return memberLevelRightCreditControllerFeign.batchMemberPriceRight(vendorRelations);
    }

    /**
     * 订单完成后，向会员服务的订单评论功能发送订单数据
     * @param order 订单
     */
    @Async
    @Override
    public void saveMemberOrderCommentAsync(OrderDO order) {
        try {
            MemberOrderCommentVO commentVO = new MemberOrderCommentVO();
            commentVO.setId(order.getId());
            commentVO.setCreateTime(order.getCreateTime());
            commentVO.setBuyerMemberId(order.getBuyerMemberId());
            commentVO.setBuyerRoleId(order.getBuyerRoleId());
            commentVO.setBuyerMemberName(order.getBuyerMemberName());
            commentVO.setVendorMemberId(order.getVendorMemberId());
            commentVO.setVendorRoleId(order.getVendorRoleId());
            commentVO.setVendorMemberName(order.getVendorMemberName());
            commentVO.setOrderNo(order.getOrderNo());
            commentVO.setShopId(order.getShopId());
            commentVO.setShopType(order.getShopType());
            commentVO.setShopEnvironment(order.getShopEnvironment());
            commentVO.setShopName(order.getShopName());
            commentVO.setOrderMode(order.getOrderMode());
            commentVO.setOrderType(order.getOrderType());
            commentVO.setOrderKind(order.getOrderKind());
            commentVO.setQuoteNo(order.getQuoteNo());
            commentVO.setDigest(order.getDigest());
            commentVO.setProductAmount(order.getProductAmount());
            commentVO.setFreight(order.getFreight());
            commentVO.setPromotionAmount(order.getPromotionAmount());
            commentVO.setCouponAmount(order.getCouponAmount());
            commentVO.setTotalAmount(order.getTotalAmount());
            commentVO.setBuyerInnerStatus(order.getBuyerInnerStatus());
            commentVO.setVendorInnerStatus(order.getVendorInnerStatus());
            commentVO.setOuterStatus(order.getOuterStatus());
            commentVO.setProducts(order.getProducts().stream().map(product -> {
                MemberOrderProductCommentVO productCommentVO = new MemberOrderProductCommentVO();
                productCommentVO.setId(product.getId());
                productCommentVO.setProductId(product.getProductId());
                productCommentVO.setSkuId(product.getSkuId());
                productCommentVO.setProductNo(product.getProductNo());
                productCommentVO.setName(product.getName());
                productCommentVO.setCategory(product.getCategory());
                productCommentVO.setBrand(product.getBrand());
                productCommentVO.setSpec(product.getSpec());
                productCommentVO.setUnit(product.getUnit());
                productCommentVO.setLogo(product.getLogo());
                productCommentVO.setPrice(product.getRefPrice());
                productCommentVO.setQuantity(product.getQuantity());
                productCommentVO.setAmount(product.getAmount());
                productCommentVO.setDeliverType(product.getDeliverType());
                productCommentVO.setAddress(product.getAddress());
                productCommentVO.setReceiver(product.getReceiver());
                productCommentVO.setPhone(product.getPhone());
                return productCommentVO;
            }).collect(Collectors.toList()));
            Wrapper<Void> result = memberOrderCommentControllerFeign.saveMemberOrderComment(commentVO);
            if (result.getCode() != ResponseCode.SUCCESS.getCode()) {
                logger.error("订单完成后，向会员服务的订单评论功能发送订单数据错误：" + result.getMessage());
            }

        } catch (Exception e) {
            logger.error("订单完成后，向会员服务的订单评论功能发送订单数据错误：" + e.getMessage());
        }
    }

    /**
     * 查询平台会员的信息
     * @param members 会员Id和角色Id列表
     * @param name    会员名称
     * @return 查询结果
     */
    @Override
    public Wrapper<List<OrderMemberQueryDTO>> findPlatformMembers(String name, List<MemberFeignVO> members) {
        Wrapper<List<MemberFeignPageQueryVO>> feignResult = memberInnerControllerFeign.findPlatformMembers(members);
        if (feignResult.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(feignResult.getCode(), feignResult.getMessage());
        }

        if (CollectionUtils.isEmpty(feignResult.getData())) {
            return Wrapper.success(new ArrayList<>());
        }

        return Wrapper.success(feignResult.getData().stream().map(member -> {
            OrderMemberQueryDTO queryVO = new OrderMemberQueryDTO();
            queryVO.setMemberId(member.getMemberId());
            queryVO.setRoleId(member.getRoleId());
            queryVO.setName(member.getName());
            queryVO.setRoleName(member.getRoleName());
            queryVO.setMemberTypeName(member.getMemberTypeName());
            queryVO.setLevel(member.getLevel());
            queryVO.setLevelTag(member.getLevelTag());
            return queryVO;
        }).collect(Collectors.toList()).stream().filter(r -> {
            if (StringUtils.hasLength(name)) {
                return r.getName().contains(name.trim());
            } else {
                return true;
            }
        }).sorted(Comparator.comparingLong(OrderMemberQueryDTO::getMemberId).thenComparingLong(OrderMemberQueryDTO::getRoleId)).collect(Collectors.toList()));
    }

    /**
     * 批量查询会员Logo
     * @param memberIds 会员Id列表
     * @return 会员logo列表
     */
    @Override
    public Wrapper<List<MemberLogoDTO>> findMemberLogos(List<Long> memberIds) {
        if (CollectionUtils.isEmpty(memberIds)) {
            return Wrapper.success(new ArrayList<>());
        }
        Wrapper<List<MemberFeignLogoVO>> logoResult = memberInnerControllerFeign.getMemberLogos(memberIds);
        if (logoResult.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(logoResult.getCode(), logoResult.getMessage());
        }

        return Wrapper.success(logoResult.getData().stream().map(result -> new MemberLogoDTO(result.getMemberId(), result.getName(), result.getLogo())).collect(Collectors.toList()));
    }

    /**
     * 查询会员Logo
     * @param memberId 会员Id
     * @return 会员logo
     */
    @Override
    public Wrapper<MemberLogoDTO> findMemberLogo(Long memberId) {
        Wrapper<List<MemberFeignLogoVO>> logoResult = memberInnerControllerFeign.getMemberLogos(Collections.singletonList(memberId));
        if (logoResult.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(logoResult.getCode(), logoResult.getMessage());
        }

        return Wrapper.success(logoResult.getData().stream().filter(member -> member.getMemberId().equals(memberId)).map(member -> new MemberLogoDTO(member.getMemberId(), member.getName(), member.getLogo())).findFirst().orElse(new MemberLogoDTO(memberId)));
    }

    /**
     * 平台后台-商户支付策略配置，查询角色类型为服务提供者的平台商户会员列表
     * @param name    会员名称
     * @param members 会员Id和角色Id列表
     * @return 查询结果
     */
    @Override
    public Wrapper<List<OrderMemberQueryDTO>> listPlatformMembers(String name, List<MemberDTO> members) {
        MemberFeignPaymentVO paymentVO = new MemberFeignPaymentVO();
        paymentVO.setName(StringUtils.hasLength(name) ? name : "");
        paymentVO.setMembers(CollectionUtils.isEmpty(members) ? new ArrayList<>() : members.stream().map(member -> {
            MemberFeignVO feignVO = new MemberFeignVO();
            feignVO.setMemberId(member.getMemberId());
            feignVO.setRoleId(member.getRoleId());
            return feignVO;
        }).collect(Collectors.toList()));

        Wrapper<List<MemberFeignPageQueryVO>> feignResult = memberInnerControllerFeign.findProviderMerchant(paymentVO);
        if (feignResult.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(feignResult.getCode(), feignResult.getMessage());
        }

        if (CollectionUtils.isEmpty(feignResult.getData())) {
            return Wrapper.success(new ArrayList<>());
        }

        return Wrapper.success(feignResult.getData().stream().map(member -> {
            OrderMemberQueryDTO queryVO = new OrderMemberQueryDTO();
            queryVO.setMemberId(member.getMemberId());
            queryVO.setRoleId(member.getRoleId());
            queryVO.setName(member.getName());
            queryVO.setRoleName(member.getRoleName());
            queryVO.setMemberTypeName(member.getMemberTypeName());
            queryVO.setLevel(member.getLevel());
            queryVO.setLevelTag(member.getLevelTag());
            return queryVO;
        }).collect(Collectors.toList()));
    }

    /**
     * SRM订单 - 查询会员入库分类 - 主营品类及结算方式信息
     * @param buyerMemberId  采购会员Id
     * @param buyerRoleId    采购会员角色Id
     * @param vendorMemberId 供应会员Id
     * @param vendorRoleId   供应会员角色Id
     * @return 查询结果
     */
    @Override
    public List<MemberCategoryDTO> findMemberBusinessCategories(Long buyerMemberId, Long buyerRoleId, Long vendorMemberId, Long vendorRoleId) {
        //Srm订单，上级会员是“采购会员”，下级会员是“供应会员”
        MemberFeignRelationVO feignVO = new MemberFeignRelationVO();
        feignVO.setUpperMemberId(buyerMemberId);
        feignVO.setUpperRoleId(buyerRoleId);
        feignVO.setSubMemberId(vendorMemberId);
        feignVO.setSubRoleId(vendorRoleId);
        try {
            logger.info("从会员服务查询结算方式参数 => " + OrderStringUtil.serializeObject(feignVO));
            Wrapper<List<MemberCategoryFeignVO>> result = memberDetailFeign.findMemberBusinessCategories(feignVO);
            if (result.getCode() != ResponseCode.SUCCESS.getCode()) {
                return new ArrayList<>();
            }

            logger.info("从会员服务查询结算方式返回 => " + OrderStringUtil.serializeObject(result));

            return CollectionUtils.isEmpty(result.getData()) ? new ArrayList<>() : result.getData().stream().map(category -> {
                MemberCategoryDTO categoryDTO = new MemberCategoryDTO();
                categoryDTO.setCategories(category.getCategories().stream().map(c -> {
                    MemberBusinessCategoryDTO businessCategoryDTO = new MemberBusinessCategoryDTO();
                    businessCategoryDTO.setLevel(c.getLevel());
                    businessCategoryDTO.setCategoryId(c.getCategoryId());
                    businessCategoryDTO.setName(c.getName());
                    return businessCategoryDTO;
                }).collect(Collectors.toList()));
                categoryDTO.setPayType(category.getPayType());
                categoryDTO.setPayTypeName(category.getPayTypeName());
                categoryDTO.setMonth(category.getMonth());
                categoryDTO.setMonthDay(category.getMonthDay());
                categoryDTO.setDays(category.getDays());
                categoryDTO.setInvoiceType(category.getInvoiceType());
                categoryDTO.setInvoiceTypeName(category.getInvoiceTypeName());
                categoryDTO.setTaxPoint(category.getTaxPoint());
                return categoryDTO;
            }).collect(Collectors.toList());
        } catch (Exception ignored) {
            return new ArrayList<>();
        }
    }

    /**
     * 查询供应商业务员用户Id
     * @param buyerMemberId  采购会员Id
     * @param buyerRoleId    采购会员角色Id
     * @param vendorMemberId 供应会员Id
     * @param vendorRoleId   供应会员角色Id
     * @return 查询结果
     */
    @Override
    public Wrapper<Long> findVendorSalesUserId(Long buyerMemberId, Long buyerRoleId, Long vendorMemberId, Long vendorRoleId) {
        OrderMemberDTO member = new OrderMemberDTO(buyerMemberId, buyerRoleId, vendorMemberId, vendorRoleId);
        Wrapper<List<OrderSalesDTO>> salesResult = findVendorSales(Collections.singletonList(member));
        if (salesResult.getCode() != ResponseCode.SUCCESS.getCode()) {
            return Wrapper.fail(salesResult.getCode(), salesResult.getMessage());
        }

        return Wrapper.success(CollectionUtils.isEmpty(salesResult.getData()) ? 0L : salesResult.getData().stream().filter(r -> r.getBuyerMemberId().equals(buyerMemberId) && r.getBuyerRoleId().equals(buyerRoleId) && r.getVendorMemberId().equals(vendorMemberId) && r.getVendorRoleId().equals(vendorRoleId)).map(OrderSalesDTO::getVendorUserId).findFirst().orElse(0L));
    }

    /**
     * 批量查询供应商业务员用户Id
     * @param buyerMemberId 采购会员id
     * @param buyerRoleId   采购会员角色Id
     * @param vendors       供应商列表
     * @return 查询结果
     */
    @Override
    public Wrapper<List<OrderSalesDTO>> findVendorSales(Long buyerMemberId, Long buyerRoleId, List<VendorBO> vendors) {
        List<OrderMemberDTO> members = vendors.stream().map(vendor -> new OrderMemberDTO(buyerMemberId, buyerRoleId, vendor.getVendorMemberId(), vendor.getVendorRoleId())).distinct().collect(Collectors.toList());
        return findVendorSales(members);
    }

    /**
     * 批量查询供应商业务员用户Id
     * @param members 采购会员与供应会员列表
     * @return 查询结果
     */
    @Override
    public Wrapper<List<OrderSalesDTO>> findVendorSales(List<OrderMemberDTO> members) {
        List<MemberFeignRelationVO> relations = members.stream().map(member -> {
            MemberFeignRelationVO relationVO = new MemberFeignRelationVO();
            relationVO.setSubMemberId(member.getBuyerMemberId());
            relationVO.setSubRoleId(member.getBuyerRoleId());
            relationVO.setUpperMemberId(member.getVendorMemberId());
            relationVO.setUpperRoleId(member.getVendorRoleId());
            return relationVO;
        }).collect(Collectors.toList());

        try {
            Wrapper<List<MemberSalesFeignVO>> salesResult = memberInnerControllerFeign.findMemberSales(relations);
            if (salesResult.getCode() != ResponseCode.SUCCESS.getCode()) {
                return Wrapper.fail(salesResult.getCode(), salesResult.getMessage());
            }

            if (CollectionUtils.isEmpty(salesResult.getData())) {
                return Wrapper.success(new ArrayList<>());
            }

            return Wrapper.success(salesResult.getData().stream().map(r ->
                    new OrderSalesDTO(r.getSubMemberId(), r.getSubRoleId(), r.getMemberId(), r.getRoleId(), r.getUserId())
            ).collect(Collectors.toList()));
        } catch (Exception ignored) {
            return Wrapper.fail(ResponseCode.SERVICE_MERCHANT_MEMBER_ERROR);
        }
    }

    /**
     * 查询用户信息
     * @param userId 用户Id
     * @return 用户信息
     */
    @Override
    public MemberUserDTO findUserDetail(Long userId) {
        MemberFeignUserIdVO idVO = new MemberFeignUserIdVO();
        idVO.setUserId(userId);
        try {
            Wrapper<MemberFeignUserDetailVO> userResult = memberDetailFeign.findMemberUser(idVO);
            if (userResult.getCode() == ResponseCode.SUCCESS.getCode() && Objects.nonNull(userResult.getData())) {
                return new MemberUserDTO(userResult.getData().getUserId(), userResult.getData().getUserName(), userResult.getData().getOrganizationName(), userResult.getData().getJobTitle());
            }

            return new MemberUserDTO(userId);
        } catch (Exception ignored) {
            return new MemberUserDTO(userId);
        }
    }

    public Wrapper<List<MemberFeignRightByOrderVO>> batchMemberPriceRightForOrder(Long buyerMemberId, Long buyerRoleId, List<MemberAndRoleIdDTO> upperMemberList) {
        MemberFeignBatchVO spendVO = new MemberFeignBatchVO();
        spendVO.setMemberId(buyerMemberId);
        spendVO.setRoleId(buyerRoleId);
        List<MemberFeignUpperMemberVO> upperMmebers = upperMemberList.stream().map(o -> {
            MemberFeignUpperMemberVO feignUpperMemberVO = new MemberFeignUpperMemberVO();
            feignUpperMemberVO.setUpperMemberId(o.getMemberId());
            feignUpperMemberVO.setUpperRoleId(o.getRoleId());
            return feignUpperMemberVO;
        }).collect(Collectors.toList());
        spendVO.setUpperMembers(upperMmebers);
        return memberLevelRightCreditControllerFeign.batchMemberPriceRightForOrder(spendVO);
    }

    /**
     * 扣减会员积分或平台积分
     * @param deductions 积分抵扣列表
     * @param order      订单
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> memberDeductionPoints(OrderDO order, List<OrderDeductionVO> deductions, BigDecimal usePoints) {
        MemberFeignRightDeductionVO deductionVO = new MemberFeignRightDeductionVO();
        deductionVO.setSubMemberId(order.getBuyerMemberId());
        deductionVO.setSubRoleId(order.getBuyerRoleId());
        deductionVO.setRelType(deductions.get(0).getRelType());
        deductionVO.setItemList(deductions.stream().map(deduction -> {
            MemberFeignRightDeductionItemVO itemVO = new MemberFeignRightDeductionItemVO();
            itemVO.setOrderNo(order.getOrderNo());
            itemVO.setUpperMemberId(deduction.getVendorMemberId());
            itemVO.setUpperRoleId(deduction.getVendorRoleId());
            itemVO.setUsedPoint(usePoints.intValue());
            return itemVO;
        }).collect(Collectors.toList()));

        return memberLevelRightCreditControllerFeign.calculateMemberDeductionRightPoint(deductionVO);
    }

    /**
     * 订单取消后，返还已抵扣的积分
     * @param order 订单
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> returnDeductionPoints(OrderDO order) {
        MemberFeignRightReturnVO returnVO = new MemberFeignRightReturnVO();
        returnVO.setOrderNo(order.getOrderNo());
        returnVO.setSubMemberId(order.getBuyerMemberId());
        returnVO.setSubRoleId(order.getBuyerRoleId());

        return memberLevelRightCreditControllerFeign.returnMemberRightPoint(returnVO);
    }
}
